<template>
	<view :id="templateId" class="container">
		<empty
      v-if="!liveList.length&&showEmpty"
			:src="baseTemplateFileUri + 'image/emptyStatus/common.png'"
		></empty>
		<template v-else>
      <uni-banner :image="baseTemplateFileUri + pageBanner.live"></uni-banner>
      <view class="live-wrap">
        <view class="live-list">
          <uni-live-col 
            v-for="(item, index) in liveList"
            :key="index"
            outClass="zz-mb24"
            pathResource="1"
            :itemInfo="item"></uni-live-col>
        </view>
      </view>
      <!--  -->
      <uni-load-more 
        v-if="liveList.length"
        :status="loadingType"></uni-load-more>
    </template>
	</view>
</template>

<script>
/* api begin */
import {
  customerRoomList
} from "@/lib/api/shopServer/info";
/* api end */

/** components begin */
import empty from "@/components/empty";
import uniBanner from "@/components/uniBanner";
import uniIcon from "@/components/uniIcon/uniIcon";
import uniLoadMore from "@/components/uniLoadMore/uniLoadMore";
import uniLiveCol from "@/components/live/uniLiveCol";
/** components end */

/** mixins begin */
import bannerMixin from "@/mixins/banner";
/** mixins end */
//let currentPage = 1;
export default {
	components: {
		uniBanner,
		uniIcon,
    empty,
    uniLoadMore,
    uniLiveCol
	},
	mixins: [
    bannerMixin
  ],
	data() {
		return {
      //
      currentPage:1,
      total:0,
      loadingType:"more",
      showEmpty:false,
      // 列表数据
			liveList: []
		};
  },

  async onLoad(){
    try {
      await this.getLiveList();
    } catch (error) {
      console.log(error);
    }
  },

  async show(){
    
  },

  //下拉刷新
	async onPullDownRefresh() {
    this.currentPage = 1;
    this.total = 0;
    this.liveList = [];
    await this.getLiveList();
    uni.stopPullDownRefresh();
  },
  
  // 上拉加载
	async onReachBottom() {
		await this.getLiveList();
	},

  methods:{
    // 获取直播间列表
    async getLiveList(){
      //
      const liveCount = this.liveList.length;
      if( liveCount && liveCount >= this.total ) {
        return Promise.resolve();
      }
      try {
        this.loadingType = "loading";
        const { data } = await customerRoomList({
          currentPage:this.currentPage,
          showLoading:false,
          appId: this.accountInfo.appId,   // appid
          shopId: this.baseShopId   // 商铺id
        },{
          isLiveList:true
        });
        console.log("liveList---",data);
        //
        if( this.currentPage === 1 ) {

          this.liveList = data.list;

        } else {

          this.liveList = this.liveList.concat(data.list);

        }
        //
        this.loadingType = "more";
        this.total = data.total;
        this.currentPage++;
        this.showEmpty = false;
        //
        if( !this.liveList.length ) {
          this.currentPage = 1;
          this.showEmpty = true;
        }
        //
        if( this.liveList.length >= data.total ) { 
          this.loadingType = "noMore";
        }
      } catch (error) {
        console.log("---获取直播间列表数据失败---",error);
        this.loadingType = "noMore";
        await this.$api.showToast(error.resultInfo || "获取直播列表数据失败");
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "@/pages/common/styles/live/live.scss";
</style>